<!-- Author: Moe Kyaw Thu Aung --> 
<!-- Last Modified: 11 Sep 2012 -->
<?php
	session_start();
	
	include("../confs/config.php");
	
	if(!$_SESSION['auth']) {
		$_SESSION['msg'] = "Please login first!";
		header("location: index.php");
		exit(0);
	}
?>
<html>
	<head>
		<title>My Book Store : Administration</title>
		<link rel="stylesheet" href="../css/admin.css" />

		<script>
			function confirm_del() {
				return confirm("Are you sure you want to delete?");
			}
		</script>
		
	</head>
	<body>
		<div id="wrapper">
			<div id="head">
				<h1>My Book Store : Item List</h1>
				<a href="actions.php?do=logout">Logout</a>
			</div>

			<?php
				if($_SESSION['msg'] != "") {
					echo '<div class="msg">' . $_SESSION['msg'] . '</div>';
					$_SESSION['msg'] = "";
				}
			?>
			
			<div id="item-list">
				
				<a class="tab this" href="list.php">Item List</a> 
				<a class="tab" href="order.php">Order List</a>
				<a class="tab" href="report.php">Feedback</a>
				
				<table width="100%" cellpadding="8" cellspacing="0">
					
					<?php
						$conn = mysql_connect($DB_HOST, $DB_USER, $DB_PASSWORD);
						mysql_select_db($DB_NAME, $conn);
						
						$result = mysql_query("SELECT * FROM items");
						
						$i = 0;
						while($row = mysql_fetch_assoc($result)) {
							$id = $row['id'];
							
							if(file_exists("../covers/".$row['cover']) && !is_dir("../covers/".$row['cover'])) {
								$cover = "../covers/".$row['cover'];
							} else {
								$cover = "../covers/no.jpg";
							}
							
							if($i % 2) $class = "even";
							else $class = "odd";
							
							echo "<tr class='$class'>";
							
							echo "<td rowspan='3' width='20'><img src='$cover' alt='Book Cover' width='120' height='144' /></td>";
							
							echo "<td><h3>" . $row['name'] . " <span>( " . $row['qty'] . " )</span> </h3></td>";
							echo "</tr>";
							
							echo "<tr class='$class' valign='top'><td><p>" . $row['des'] . "</p></td></tr>";
							echo "<tr class='$class'><td><span>$" . $row['price'] . "</span>";

							echo "<a href='actions.php?do=delete&id=$id' class='action' onclick='return confirm_del()'><img src='../admin/images/del_ico.png' /></a>";
							echo "<a href='edit.php?id=$id' class='action'><img src='../admin/images/edit_ico.png' /></a>";
							echo "</td></tr>";
							
							$i++;
						}
					?>
					
					<tr>
						<td colspan="2" align="right">
							<a href="new.php" class='new-link'>Add new Item</a>
						</td>
					</tr>
					
				</table>
			</div>
			
			<div id="foot">
				&copy; OneStop JCU.
			</div>
		</div>
	</body>
</html>
